#ifndef __SRVMGR_INNERLOCK_H__
#define __SRVMGR_INNERLOCK_H__


#ifdef __cplusplus


class CSrvNullCriticalSection
{
public:
	void Lock() {}
	void Unlock() {}
	CSrvNullCriticalSection() {}
	~CSrvNullCriticalSection() {}
};

class CSrvCriticalSection
{
public:
	CSrvCriticalSection()
	{
#ifndef __GNUC__
		InitializeCriticalSection(&m_sec);
#else
		pthread_mutex_init(&m_sec, NULL);
#endif
	}
	~CSrvCriticalSection()
	{
#ifndef __GNUC__
		DeleteCriticalSection(&m_sec);
#else
		pthread_mutex_destroy(&m_sec);
#endif
	}

	void Lock()
	{
#ifndef __GNUC__
		EnterCriticalSection(&m_sec);
#else
		pthread_mutex_lock(&m_sec);
#endif
	}
	void Unlock()
	{
#ifndef __GNUC__
		LeaveCriticalSection(&m_sec);
#else
		pthread_mutex_unlock(&m_sec);
#endif
	}
#ifndef __GNUC__
	CRITICAL_SECTION m_sec;
#else
	pthread_mutex_t m_sec;
#endif
};

template<class LockType>
class CSrvCriticalSectionAtuoLock
{
public:
	LockType* m_lock;
	
	CSrvCriticalSectionAtuoLock(LockType* lock):m_lock(lock)
	{
		m_lock->Lock();
	}

	~CSrvCriticalSectionAtuoLock()
	{
		m_lock->Unlock();
	}
};

#endif

#endif